package models

import (
	"database/sql"
	_ "github.com/go-sql-driver/mysql"
)

type DB struct {
	*sql.DB
}

func NewDB(dataSourceName string) (*DB, error) {
	db, err := sql.Open("mysql", dataSourceName)
	checkErr(err)

	db.SetMaxOpenConns(2000)
	db.SetMaxIdleConns(1000)
	err = db.Ping()
	checkErr(err)

	return &DB{db}, nil
}

func checkErr(err error) {
	if err != nil {
		panic(err)
	}
}
